sos = input()
mx = 0
if len (sos) == 4:
    a = [sos[0], sos[1], sos[2], sos[3], sos[0:2], sos[1:3], sos[2:4], sos[0:3], sos[1:4], sos]
    for j in range (len(a)):
        n = int(a[j])
        c = 2
        for l in range (2,n//+1):
            if n%l == 0:
                c=c+1
        if c == 2 and n != 1:
            mx = max(mx,n)
print(mx)
            
